<?php
/**
 * @copyright Copyright (c) 2021 勾股工作室
 * @license https://opensource.org/licenses/Apache-2.0
 * @link https://www.gougucms.com
 */

namespace app\admin\model;

use think\facade\Session;
use think\Model;
use think\facade\Db;

class Data extends Model
{
	private $school;

	public function __construct(array $data = [])
	{
		parent::__construct($data);

		$session_admin = get_config('app.session_admin');
		$uid = Session::get($session_admin)['id'];

		$this->school = Db::name('admin')->where(['id' => $uid])->value("school");
	}

	public function getKindAttr($value)
	{
		return Db::name('DataConfig')->where(['type' => 'table', 'value' => $value, 'status' => 1, 'school' => $this->school])->value('name');
	}

	public function getOpAttr($value)
	{
		return Db::name('DataConfig')->where(['type' => 'op', 'value' => $value, 'status' => 1, 'school' => $this->school])->value('name');
	}

	public function getPaperAttr($value)
	{
		return Db::name('DataConfig')->where(['type' => 'paper', 'value' => $value, 'status' => 1, 'school' => $this->school])->value('name');
	}

	public function getDoubleAttr($value)
	{
		$map = [0 => '单', 1 => '双'];
		return $map[$value];
	}
}
